<?php
/*
 * @package Webhosting Component
 * @copyright Copyright (C) 2007 Jonas Brand. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * Official website: http://wh-com.de
 */

/*
* Sicherstellen, dass das Script nicht direkt aufgerufen wird
*/
defined( '_VALID_MOS' ) or die('Direct Access to this acript is not allowrd');

function upgradeDatabase() {
    if (defined( '_JEXEC' )) {
        $database = JFactory::GetDBO();
    } else {
        global $database;
    }
    $errors='';
    $query="ALTER TABLE #__wh_orders ADD street2 VARCHAR( 200 ) NOT NULL COMMENT 'Total Fees' AFTER street1";
    $queries="<br/><br/>".$query;
    $database->setQuery($query);
    if(!$database->query()) {
        $errors.=$database->getErrorMsg().'<br/><br/>';
    }

    $query="ALTER TABLE #__wh_plans ADD tldprices VARCHAR( 255 ) NOT NULl AFTER tlds";
    $queries.="<br/><br/>".$query;
    $database->setQuery($query);
    if(!$database->query()) {
        $errors.=$database->getErrorMsg().'<br/><br/>';
    }

    $query="UPDATE #__wh_plans SET payment='12' WHERE payment NOT IN ('1','3','6','12','24')";
    $queries.="<br/><br/>".$query;
    $database->setQuery($query);
    if(!$database->query()) {
        $errors.=$database->getErrorMsg().'<br/><br/>';
    }

    $query="UPDATE #__wh_plans SET tldprices='9.99,11.99' WHERE tldprices = ''";
    $queries.="<br/><br/>".$query;
    $database->setQuery($query);
    if(!$database->query()) {
        $errors.=$database->getErrorMsg().'<br/><br/>';
    }

    $query="ALTER TABLE `#__wh_plans` CHANGE `payment` `payment` TINYINT( 2 ) NULL DEFAULT NULL";
    $queries.="<br/><br/>".$query;
    $database->setQuery($query);
    if(!$database->query()) {
        $errors.=$database->getErrorMsg().'<br/><br/>';
    }

    $query="UPDATE #__wh_features SET value='[billing_cycle]' WHERE value='[payment]'";
    $queries.="<br/><br/>".$query;
    $database->setQuery($query);
    if(!$database->query()) {
        $errors.=$database->getErrorMsg().'<br/><br/>';
    }

    $query="ALTER TABLE #__wh_plans ADD `catid` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `id_vhcs`;";
    $queries.="<br/><br/>".$query;
    $database->setQuery($query);
    if(!$database->query()) {
        $errors.=$database->getErrorMsg().'<br/><br/>';
    }

    $debug  = "<h3>Errors:</h3>";
    $debug .= $errors;
    $debug .= "<h3>MySQL-Queries:</h3>";
    $debug .= $queries;
    // Uncomment this line to activate debugging
    # echo $debug;
}

function com_install() {
        upgradeDatabase();
	echo '
				<table class="adminheading">

		<tr>
			<th class="install">
			Webhosting Component</th>
		</tr>
		</table>

		<table class="adminform">
		<tr>
			<td align="left"><strong>
Homepage:<br />
<a href="http://wh-com.de">www.wh-com.de</a><br />
Support-Forum:<br />
<a href="http://forum.wh-com.de">forum.wh-com.de</a><br />
E-Mail:<br />
<a href="mail:info@wh-com.de">info@wh-com.de</a><br /></strong>
			</td>
		</tr>
		<tr>
			<td colspan="2" align="center">
			[&nbsp;<a href="index2.php?option=com_webhosting&task=loadSampledata" style="font-size: 16px; font-weight: bold">Load Sampledata ...</a>&nbsp;]
			</td>
		</tr>

		</table><br/><br/>
';
}
?>
